function myNew(fn, ...args) {
    if (args.length === 1 && Array.isArray(args[0])) {
        args = args[0]
    }
    const self = Object.create(fn.prototype)
    const result = fn.apply(self, args)
    return (result && typeof result === 'object') ? result : self;
}


function Animal(name, color) {
    this.name = name
    this.color = color
    console.log(this)
}

Animal.prototype = {
    constructor: Animal,
    hello() {
        console.log(this.name, 'say hello')
    }
}


const cat = myNew(Animal, 'Kitty', 'white')
cat.hello()


const dog = myNew(Animal, ['Husky', 'black'])
dog.hello()